
<h2>Tournament Report</h2>
    <table>
    <tr>
    <th>Name</th>
    <th>Date</th>
    <th>Location</th>
    </tr>
    <tr>
        <td>
            <?php echo $tournament['Tournament']['name']; ?>
        </td>
        <td>
            <?php echo $tournament['Tournament']['date']; ?>
        </td>
        <td>
            <?php echo $tournament['Tournament']['location']; ?>
        </td>
        <td>
            <?php echo $tournament['Tournament']['tournament_notes']; ?>
        </td>
    </tr>
    </table>
    <h2>Compiled Data</h2>
<hr/>

<?php
    echo "<h3>Churches Summary</h3>\n";
    echo "<textarea cols=70 rows=15>Church Name, Conference, Coach Name, Coach Email, Daytime Phone, Evening Phone, Lunch Count, Seats Count\n";
    foreach($tournament['Registration'] as $registration):
        echo $registration['church_name'] . ', ' .
             $registration['conference'] . ', ' .
             $registration['coach_name'] . ', ' .
             $registration['email'] . ', ' .
             $registration['daytime_phone'] . ', ' .
             $registration['evening_phone'] . ', ' .
             $registration['number_for_lunch'] . ', ' .
             $registration['number_of_seats'] . "\n";
    endforeach;
    echo "</textarea>\n";

    $churches_total = 0;
    $conferences_total = 0;
    $teams_total = 0;
    $individuals_total = 0;
    $number_for_lunch_total = 0;
    $number_of_seats_total = 0;
    $conferences = array();
    foreach($tournament['Registration'] as $registration):
        $conferences[] = $registration['conference'];
        $churches_total++;
        $number_for_lunch_total += $registration['number_for_lunch'];
        $number_of_seats_total += $registration['number_of_seats'];
        foreach($registration['Team'] as $team) $teams_total++;
        foreach($registration['Individual'] as $individual) $individuals_total++;
    endforeach;
    $conferences_total = count(array_unique($conferences));

?>
    <p>Totals: Churches: <?php echo $churches_total ?>, Conferences: <?php echo $conferences_total; ?>, Teams: <?php echo $teams_total; ?>, Individuals: <?php echo $individuals_total; ?>, Lunch: <?php echo $number_for_lunch_total; ?>, Seats: <?php echo $number_of_seats_total; ?>
</p>
<hr/>

<?php
    //print out a summary of all the teams

    //collect all the teams by division
    $teams = array('STVA'=>array(),'STVB'=>array(),'STR'=>array(), 'YTVA'=>array(),'YTVB'=>array(),'YTRA'=>array(),'YTRB'=>array(), 'RO'=>array());
    foreach($tournament['Registration'] as $registration):
        foreach($registration['Team'] as $team):
            $teams[$team['division']][] = $registration['church_name'];
        endforeach;
    endforeach;
    //now make a table for each division with the teams in them
    echo "<h3>Teams Summary</h3>\n";
    foreach(array('STVA','STVB','STR','YTVA','YTVB','YTRA','YTRB','RO') as $division):
        echo "<h4>".$division."</h4>\n";
        echo "<table>\n";
        echo "<tr><th>Number</th><th>Team</th></tr>\n";
        sort($teams[$division]);
        foreach($teams[$division] as $team):
            echo "<tr><td>&nbsp;</td><td>" . $team . "</td></tr>\n";
        endforeach;
        echo "</table>\n";
    endforeach;
?>
<hr/>

<?php
    //print out a summary of all the individuals
    $individuals = array('STVA'=>array(),'STVB'=>array(),'STR'=>array(),'YTVA'=>array(),'YTVB'=>array(),'YTR'=>array());
    foreach($tournament['Registration'] as $registration):
        foreach($registration['Individual'] as $individual):
            $individuals[$individual['division']][] = array('name'=>$individual['name'], 'church_name'=>$registration['church_name']);
        endforeach;
    endforeach;
    echo "<h3>Individuals Summary</h3>\n";
    foreach(array('STVA','STVB','STR','YTVA','YTVB','YTR') as $division):
        echo "<h4>".$division."</h4>\n";
        echo "<table>\n";
        echo "<tr><th>Name</th><th>Church</th></tr>\n";
        foreach($individuals[$division] as $individual):
            echo "<tr><td>" . $individual['name'] . "</td><td>" . $individual['church_name'] . "</td></tr>\n";
        endforeach;
        echo "</table>\n";
    endforeach;
?>
<hr/>
<?php
    echo "<h3>Quizmasters Summary</h3>\n";
    echo "<textarea cols=70 rows=15>Name, Church Name, Divisions\n";
    foreach($tournament['Registration'] as $registration):
        foreach($registration['Quizmaster'] as $quizmaster):
            echo $quizmaster['name'] . ', ' . $registration['church_name'] .
            ($quizmaster['can_do_STVA'] ? ', STVA' : '') .
            ($quizmaster['can_do_STVB'] ? ', STVB' : '') .
            ($quizmaster['can_do_STR']  ? ', STR'  : '') .
            ($quizmaster['can_do_YTVA'] ? ', YTVA' : '') .
            ($quizmaster['can_do_YTVB'] ? ', YTVB' : '') .
            ($quizmaster['can_do_YTRA'] ? ', YTRA' : '') .
            ($quizmaster['can_do_YTRB'] ? ', YTRB' : '') .
            ($quizmaster['can_do_RO']   ? ', RO'   : '');
            echo "\n";
        endforeach;
    endforeach;
    echo "</textarea>\n";
?>
<hr/>

<?php
    echo "<h3>Housing Summary</h3>\n";
    foreach($tournament['Registration'] as $registration):
        echo "<h4>" . $registration['church_name'] . "</h4>\n";
        echo "<table>\n";
        echo "<tr><th>Name</th><th>Type</th></tr>\n";
        foreach($registration['Housee'] as $housee):
            echo "<tr><td>" . $housee['name'] . "</td><td>" . $housee['type'] . "</td></tr>\n";
        endforeach;
        echo "</table>\n";
        echo "<p>Notes: " . $registration['notes'] . "</p>\n";
        echo "<br/>\n";
    endforeach;


    echo "</pre>\n";
?>
